package com.gwnet.shop.controller;

import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gwnet.shop.domain.OrderEvaluate;
import com.gwnet.shop.service.IOrderEvaluateService;

import javax.annotation.Resource;

/**
 * 商品评价Controller
 * @author zhangwanpeng
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/evaluate")
public class OrderEvaluateController extends MBaseController
{
    @Resource
    private IOrderEvaluateService orderEvaluateService;

    /**
     * 查询商品评价列表
     */
    @SaCheckPermission("shop:evaluate:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderEvaluate orderEvaluate)
    {
        startPage();
        List<OrderEvaluate> list = orderEvaluateService.selectOrderEvaluateList(orderEvaluate);
        return getDataTable(list);
    }


    /**
     * 根据店铺id 查询商品评价列表
     */
    @SaCheckPermission("shop:evaluate:list")
    @GetMapping("/tenant/{tenantId}")
    public TableDataInfo list(@PathVariable Long tenantId)
    {
        startPage();
        List<OrderEvaluate> list = orderEvaluateService.selectOrderEvaluateListByTenantId(tenantId);
        return getDataTable(list);
    }


    /**
     * 获取商品评价详细信息
     */
    @SaCheckPermission("shop:evaluate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderEvaluateService.selectOrderEvaluateById(id));
    }

    /**
     * 新增商品评价
     */
    @SaCheckPermission("shop:evaluate:add")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderEvaluate orderEvaluate)
    {
        return toAjax(orderEvaluateService.insertOrderEvaluate(orderEvaluate));
    }

    /**
     * 修改商品评价
     */
    @SaCheckPermission("shop:evaluate:edit")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderEvaluate orderEvaluate)
    {
        return toAjax(orderEvaluateService.updateOrderEvaluate(orderEvaluate));
    }

    /**
     * 删除商品评价
     */
    @SaCheckPermission("shop:evaluate:remove")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderEvaluateService.deleteOrderEvaluateByIds(ids));
    }
}
